# coding:utf-8
# -*- coding:utf-8 -*-

import pandas as pd

max_num2 = 0





def max_num(l1):
    global max_num2
    max_num1 = sorted(l1)[-1]
    if(max_num1 > max_num2):
        max_num2 = max_num1

    return  max_num2

def max_num_for_grid(df):
    for i in range(0, 19):
        for j in range(0, 19):
            num_list = []

            if(i < 3 and j < 3) :
                a1 = df.ix[i][j] * df.ix[i+1][j] * df.ix[i+2][j] * df.ix[i+3][j]
                a2 = df.ix[i][j] * df.ix[i][j+1] * df.ix[i][j+2] * df.ix[i][j+3]
                a3 = df.ix[i][j] * df.ix[i+1][j+1] * df.ix[i+2][j+2] * df.ix[i+3][j+3]
                num_list.append(a1)
                num_list.append(a2)
                num_list.append(a3)

                max_num2 = max_num(num_list)

            elif(i < 3 and j >= 17):
                a1 = df.ix[i][j] * df.ix[i][j-1] * df.ix[i][j-2] * df.ix[i][j-3]
                a2 = df.ix[i][j] * df.ix[i+1][j] * df.ix[i+2][j] * df.ix[i+3][j]
                a3 = df.ix[i][j] * df.ix[i+1][j-1] * df.ix[i+2][j-2] * df.ix[i+3][j-3]

                num_list.append(a1)
                num_list.append(a2)
                num_list.append(a3)

                max_num2 = max_num(num_list)

            elif(i >=17 and j >= 17):
                a1 = df.ix[i][j] * df.ix[i-1][j] * df.ix[i-2][j] * df.ix[i-3][j]
                a2 = df.ix[i][j] * df.ix[i][j-1] * df.ix[i][j-2] * df.ix[i][j-3]
                a3 = df.ix[i][j] * df.ix[i-1][j-1] * df.ix[i-2][j-2] * df.ix[i-3][j-3]

                num_list.append(a1)
                num_list.append(a2)
                num_list.append(a3)

                max_num2 = max_num(num_list)

            elif(i >= 17 and j < 3):
                a1 = df.ix[i][j] * df.ix[i][j+1] * df.ix[i][j+2] * df.ix[i][j+3]
                a2 = df.ix[i][j] * df.ix[i-1][j] * df.ix[i-2][j] * df.ix[i-3][j]
                a3 = df.ix[i][j] * df.ix[i-1][j+1] * df.ix[i-2][j+2] * df.ix[i-3][j+3]

                num_list.append(a1)
                num_list.append(a2)
                num_list.append(a3)

                max_num2 = max_num(num_list)

            elif(3<=i<=16 and j<3):
                a1 = df.ix[i][j] * df.ix[i + 1][j] * df.ix[i + 2][j] * df.ix[i + 3][j]
                a2 = df.ix[i][j] * df.ix[i][j + 1] * df.ix[i][j + 2] * df.ix[i][j + 3]
                a3 = df.ix[i][j] * df.ix[i + 1][j + 1] * df.ix[i + 2][j + 2] * df.ix[i + 3][j + 3]
                a4 = df.ix[i][j] * df.ix[i-1][j] * df.ix[i-2][j] * df.ix[i-3][j]
                a5 = df.ix[i][j] * df.ix[i-1][j+1] * df.ix[i-2][j+2] * df.ix[i-3][j+3]

                num_list.append(a1)
                num_list.append(a2)
                num_list.append(a3)
                num_list.append(a4)
                num_list.append(a5)

                max_num2 = max_num(num_list)

            elif(3 <= i <= 16 and j >= 17):
                a1 = df.ix[i][j] * df.ix[i][j-1] * df.ix[i][j-2] * df.ix[i][j-3]
                a2 = df.ix[i][j] * df.ix[i+1][j] * df.ix[i+2][j] * df.ix[i+3][j]
                a3 = df.ix[i][j] * df.ix[i-1][j] * df.ix[i-2][j] * df.ix[i-3][j]
                a4 = df.ix[i][j] * df.ix[i-1][j-1] * df.ix[i-2][j-2] * df.ix[i-3][j-3]
                a5 = df.ix[i][j] * df.ix[i+1][j-1] * df.ix[i+2][j-2] * df.ix[i+3][j-3]

                num_list.append(a1)
                num_list.append(a2)
                num_list.append(a3)
                num_list.append(a4)
                num_list.append(a5)

                max_num2 = max_num(num_list)

            elif(i < 3 and 3 <= j <= 16):
                a1 = df.ix[i][j] * df.ix[i+1][j] * df.ix[i+2][j] * df.ix[i+3][j]
                a2 = df.ix[i][j] * df.ix[i][j-1] * df.ix[i][j-2] * df.ix[i][j-3]
                a3 = df.ix[i][j] * df.ix[i][j+1] * df.ix[i][j+2] * df.ix[i][j+3]
                a4 = df.ix[i][j] * df.ix[i+1][j+1] * df.ix[i+2][j+2] * df.ix[i+3][j+3]
                a5 = df.ix[i][j] * df.ix[i+1][j-1] * df.ix[i+2][j-2] * df.ix[i+3][j-3]

                num_list.append(a1)
                num_list.append(a2)
                num_list.append(a3)
                num_list.append(a4)
                num_list.append(a5)

                max_num2 = max_num(num_list)

            elif(i>= 17 and 3 <= j <= 16):

                a1 = df.ix[i][j] * df.ix[i][j+1] * df.ix[i][j+2] * df.ix[i][j+3]
                a2 = df.ix[i][j] * df.ix[i-1][j] * df.ix[i-2][j] * df.ix[i-3][j]
                a3 = df.ix[i][j] * df.ix[i][j-1] * df.ix[i][j-2] * df.ix[i][j-3]
                a4 = df.ix[i][j] * df.ix[i-1][j+1] * df.ix[i-2][j+2] * df.ix[i-3][j+3]
                a5 = df.ix[i][j] * df.ix[i-1][j-1] * df.ix[i-2][j-2] * df.ix[i-3][j-3]

                num_list.append(a1)
                num_list.append(a2)
                num_list.append(a3)
                num_list.append(a4)
                num_list.append(a5)

                max_num2 = max_num(num_list)

            elif(3 <= i <= 16 and 3 <= j <= 16):
                a1 = df.ix[i][j] * df.ix[i][j - 1] * df.ix[i][j - 2] * df.ix[i][j - 3]
                a2 = df.ix[i][j] * df.ix[i][j + 1] * df.ix[i][j + 2] * df.ix[i][j + 3]
                a3 = df.ix[i][j] * df.ix[i - 1][j] * df.ix[i - 2][j] * df.ix[i - 3][j]
                a4 = df.ix[i][j] * df.ix[i + 1][j] * df.ix[i + 2][j] * df.ix[i + 3][j]
                a5 = df.ix[i][j] * df.ix[i - 1][j - 1] * df.ix[i - 2][j - 2] * df.ix[i - 3][i - 3]
                a6 = df.ix[i][j] * df.ix[i + 1][j + 1] * df.ix[i + 2][j + 2] * df.ix[i + 3][j + 3]
                a7 = df.ix[i][j] * df.ix[i+1][j-1] * df.ix[i+2][j-2] * df.ix[i+3][j-3]
                a8 = df.ix[i][j] * df.ix[i-1][j+1] * df.ix[i-2][j+2] * df.ix[i-3][j+3]

                num_list.append(a1)
                num_list.append(a2)
                num_list.append(a3)
                num_list.append(a4)
                num_list.append(a5)
                num_list.append(a6)
                num_list.append(a7)
                num_list.append(a8)

                max_num2 = max_num(num_list)

    return max_num2

def main():
    df = pd.read_csv("E:\\scala_example\\src\\main\\scala\\data\\11.txt", header=None, delimiter=" ")
    max_num2 = max_num_for_grid(df)

    print(max_num2)

if __name__ == '__main__':
    main()
